#ifndef __APP_TIMER__H__
#define __APP_TIMER__H__
#include "stm32f4xx.h"
#define DEBOUNC_TICKETS      10
//#define                      

typedef enum {
    SYSTEM_TIMER = 0,
    JUMP_TO_APP_TIMEOUT_TIMER = 1,
    CONTENT_SHOW_0NE_S_ON = 2,
    CONTENT_SHOW_0NE_HALF_S_OFF = 3,
    SCREEN_SHOW_NORMAL_DELAY_TIMER = 4,
    SCREEN_BOX_CHANGE_DELAY_TIMER = 5,
    SCREEN_SETTEMP_CHANGE_DELAY_TIMER = 6,
    SCREEN_FAN_CHANGE_DELAY_TIMER,
    SCREEN_MODE_CHANGE_DELAY_TIMER,
    BASE_BUTTON_DEBOUNCE_TIMER = 60,
    BASE_BUTTON_LONG_PRESS_TIMER = 80,
    BASE_BUTTON_SHORT_STATUS_CHANGE_TIMER = 100,
    BASE_BUTTON_LONG_STATUS_CHANGE_TIMER = 120,
    TIMER_MAX


} App_Timer_Number;

typedef struct {
    unsigned int timer_begine_tickets;
    unsigned int timer_tickets_long;
    unsigned int store_suspend_remain_tickets;
    unsigned char timer_statuse;
} App_Timer_Object;



extern App_Timer_Object App_software_timer[TIMER_MAX];

typedef enum {
    APP_TM_STANDBY = 0,
    APP_TM_RUNNING_OUT,
    APP_TM_RUNNING,
    APP_TM_SUSPENSIVE,

} APP_TIMER_STATUS_TYPE;





void App_Timer_Init(void);

unsigned int App_ticket_1ms_Get(void);

void App_Timer_delay_ms(unsigned int timer_ticket_long);

void Start_App_Software_Timer(unsigned char Timer_No, unsigned int Timer_ticket_long);

void Suspend_App_Software_Timer(unsigned char Timer_No);

void Continue_App_Software_Timer(unsigned char Timer_No);

unsigned char App_Software_Timer_Status(unsigned char Timer_No);

unsigned char Get_App_Software_Timer_Info(unsigned char Timer_No, unsigned int* tickets_remain);

void Stop_App_Software_Timer(unsigned char Timer_No);

void App_SysTick_Handler(void);



static unsigned int get_timer_begin_tickets(unsigned char Timer_No);
static unsigned int get_timer_need_elapsed_tickets(unsigned char Timer_No);
static unsigned char get_timer_status(unsigned char Timer_No);
static unsigned int get_timer_stored_remian_tickets(unsigned char Timer_No);
static void store_timer_remain_tickets(unsigned int Timer_No, unsigned int remain_tickets);
static void set_timer_status(unsigned char Timer_No, unsigned char status);
static void set_timer_begin_tickets(unsigned int Timer_No, unsigned int begin_tickets);
static void set_timer_need_elapsed_tickets(unsigned int Timer_No, unsigned int need_elapsed_tickets);
static unsigned char calculate_tickets(unsigned int begin_tickets, unsigned int now_tickets, unsigned int need_elapsed_tickets, unsigned int* remain_tickets);


#endif
